package testJdk.base.juc_test.multi_threading.lock;

/**
 * @ClassName : learn_jdk.multi_threading.lock.LockTest
 * @Description : 类描述
 * Created by cyd on 2021-03-27 20:23:47
 */
public class LockTest {
    public static void main(String[] args) throws InterruptedException {
        A a = new A();
        long start = System.currentTimeMillis();
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 10000000; i++) {
                a.increase();
            }
        });
        t1.start();
        // 两个线程操作同一个对象
        for (int i = 0; i < 10000000; i++) {
            a.increase();
        }
        // join()方法只会使主线程(或者说调用t.join()的线程)进入等待池并等待t线程执行完毕后才会被唤醒。
        // 并不影响同一时刻处在运行状态的其他线程。
        t1.join();
        long end = System.currentTimeMillis();
        System.out.printf("%sms%n", end - start);
        System.out.println(a.getNum());

    }
}
